function filename() {
	var d = new Date();
	var y = d.getFullYear();
	var m = d.getMonth() + 1;
	var date = d.getDate();
	var h = d.getHours();
	var min = d.getMinutes();
	var s = d.getSeconds();
	var mo = m<10?'0'+m:''+m;
	var dd = date<10?'0'+date:''+date;
	var hh = h<10?'0'+h:''+h;
	var mm = min<10?'0'+min:''+min;
	var ss = s<10?'0'+s:''+s;      
	var fn = y + mo + dd + hh + mm + ss;
	return fn;
}


document.getElementById('button_window').onclick = function () {
    console.log(document.documentElement.style.overflow);
	chrome.tabs.query({ active: true, currentWindow: true }, function(tabs){
        chrome.tabs.executeScript(tabs[0].id, { code: "document.documentElement.style.overflow = 'hidden';" } );
        setTimeout(function(){
            chrome.tabs.captureVisibleTab({format:"png"}, function(dataUrl){
                chrome.tabs.executeScript(tabs[0].id, { code: "document.documentElement.style.overflow = '';" } );
                //var data = dataUrl;
                var image = new Image();
                image.src = dataUrl;
                image.onload = function(){
                    var canvas = document.createElement("canvas");
                    canvas.width = image.width;
                    canvas.height = image.height;
                    var context = canvas.getContext("2d");
                    context.drawImage(image, 0, 0);
                    var link = document.createElement('a');
                    link.download = document.title + filename() + '_' + canvas.width + 'X' + canvas.height;
                    link.href = canvas.toDataURL("image/png", 1.0);
                    link.click();
                    //data = '';
                    chrome.notifications.create('', { type:'basic', iconUrl:'icon.png', title:'保存路径：', message:link.download });
                };
            });
        }, 1000);
	});
};

document.getElementById('button_video').onclick = function () {
	chrome.tabs.executeScript({ file: 'capture.js' });
    //browser.tabs.executeScript({ file: 'capture.js' }); //firefox
};



